package cn.gailvlun.gll.presentation.apartment.task;

import android.arch.lifecycle.ViewModelProviders;
import android.content.Context;
import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;

import cn.gailvlun.gll.R;
import cn.gailvlun.gll.databinding.ActivityTodayTaskBinding;
import cn.gailvlun.gll.net.apartment.room.ApartmentTask;
import cn.gailvlun.gll.presentation.apartment.task.vm.TodayTaskViewModel;
import cn.gailvlun.gll.presentation.base.BaseActivity;
import cn.gailvlun.gll.widget.NavigationBarView;



public class TodayTaskActivity extends BaseActivity {

    public static void openActivity(Context context, ApartmentTask task) {
        Intent intent = new Intent(context, TodayTaskActivity.class);
        intent.putExtra("taskId", task.getId());
        context.startActivity(intent);
    }

    private ActivityTodayTaskBinding mBinding;
    private TodayTaskViewModel mViewModel;

    @Override
    protected void initComponent() {
        mBinding = DataBindingUtil.setContentView(this, R.layout.activity_today_task);
        mBinding.setPresenter(new Presenter());
    }

    @Override
    protected void createHandler() {
        mBinding.nbv.setOnBackListener(new NavigationBarView.OnBackListener() {
            @Override
            public void onBack(NavigationBarView nb) {
                onBackPressed();
            }
        });
    }

    @Override
    protected void loadData(@Nullable Bundle savedInstanceState) {
        Integer taskId = getIntent().getIntExtra("taskId", -1);

        mViewModel = ViewModelProviders.of(this).get(TodayTaskViewModel.class);

        if (taskId != -1) {
            ApartmentTask todayTask = mViewModel.getTaskById(taskId);
            mBinding.setItem(todayTask);
        }
    }

    public class Presenter {
        public void goToCheckIn(ApartmentTask task) {
            CheckInActivity.openActivity(mContext, task);
        }
    }
}
